package cn.swust.creathtml;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.swust.model.InformationBean;
import cn.swust.model.ProductBean;
import cn.swust.service.InformationService;
import cn.swust.service.ProductService;
import cn.swust.service.serviceimpl.InformationServiceImpl;
import cn.swust.service.serviceimpl.ProductServiceImpl;
import cn.swust.util.StaticFreemarker;

import com.opensymphony.xwork2.ActionSupport;

import freemarker.template.TemplateException;

public class IndexHtmlAction extends ActionSupport {
	private InformationService infoSer = new InformationServiceImpl();
	private ProductService proSer = new ProductServiceImpl();
	
	private List<ProductBean> proList= new ArrayList<ProductBean>();
	private List<InformationBean> newsList = new ArrayList<InformationBean>();
	public String refresh()
	{
		StaticFreemarker sf = new StaticFreemarker();  
		proList = proSer.queryLastProByTime(9);
		newsList = infoSer.queryCountByType(5, 0);
		System.out.println("freemaker:首页数据成功查询");
		Map<String,List<InformationBean>> map = new HashMap<String,List<InformationBean>>(); 
		map.put("newsList", newsList);
		String htmlfile = "home.html";  
		  
        try {  
            sf.init("home.ftl", htmlfile, newsList, "WEB-INF");  
        } catch (IOException e) {  
            e.printStackTrace();  
        } catch (TemplateException e) {  
            e.printStackTrace();  
        }  
		return SUCCESS;
	}
	public InformationService getInfoSer() {
		return infoSer;
	}
	public void setInfoSer(InformationService infoSer) {
		this.infoSer = infoSer;
	}
	public ProductService getProSer() {
		return proSer;
	}
	public void setProSer(ProductService proSer) {
		this.proSer = proSer;
	}
	public List<ProductBean> getProList() {
		return proList;
	}
	public void setProList(List<ProductBean> proList) {
		this.proList = proList;
	}
	public List<InformationBean> getNewsList() {
		return newsList;
	}
	public void setNewsList(List<InformationBean> newsList) {
		this.newsList = newsList;
	}
	
}
